package com.kyc.kycxkplaygame.view.digital;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;
import com.kyc.kycxkplaygame.R;
import com.kyc.kycxkplaygame.entity.digital.DigitalBlockUnit;

/**
 * Created by Administrator on 2018/7/16.
 */

public class DigitalBgView extends View {
    /**
     * 网格开始坐标值，横纵坐标的开始值都是此值
     */
    public static final int beginPoint = 10;
    /**
     * 俄罗斯方块的最大坐标
     */
    private static int max_x, max_y;
    /**
     * 行数和列数
     */
    private static int num_x = 0, num_y = 0;
    /**
     * 背景墙画笔
     */
    private static Paint paintWall = null;

    private static final int BOUND_WIDTH_OF_WALL = 1;

    /**
     * 俄罗斯方块颜色数组
     */
    //private static final int color[] = { Color.parseColor("#FF6600"), Color.BLUE, Color.RED, Color.GREEN, Color.GRAY };
    private static final int color[] = {R.color.c_ffa4c0,
            R.color.c75cf3,
            R.color.c_0c36d2,
            R.color.c_f60fcd,
            R.color.c_2bd0d6,
            R.color.c_1fac7f,
            R.color.f54a15,
            R.color.c_5f9d0e,
            R.color.c_2095f2,
            R.color.c_ffee9900,
            R.color.colorRed};
    /**
     * 分数
     */
    private int score = 0;
    private int lastX;
    private int lastY;

    /**
     * 当前方块的类型
     */
    //private int blockType = 0;
    public DigitalBgView(Context context) {
        this(context, null);
    }

    public DigitalBgView(Context context, AttributeSet attrs) {
        super(context, attrs);
        if (paintWall == null) {// 初始化化背景墙画笔
            paintWall = new Paint();
            paintWall.setColor(Color.LTGRAY);
            paintWall.setStyle(Paint.Style.STROKE);
            paintWall.setStrokeWidth(BOUND_WIDTH_OF_WALL + 1);
        }
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        max_x = getWidth();
        max_y = getHeight();
        RectF rel;
        // 绘制网格
        num_x = 0;
        num_y = 0;
        for (int i = beginPoint; i < max_x - DigitalBlockUnit.UNIT_SIZE; i += DigitalBlockUnit.UNIT_SIZE) {
            for (int j = beginPoint; j < max_y - DigitalBlockUnit.UNIT_SIZE; j += DigitalBlockUnit.UNIT_SIZE) {
                rel = new RectF(i, j, i + DigitalBlockUnit.UNIT_SIZE, j + DigitalBlockUnit.UNIT_SIZE);
                canvas.drawRoundRect(rel, 8, 8, paintWall);
                num_y++;
            }
            num_x++;
        }
    }
}
